
#include "power.h"

power_info cur_powerinfo;

void init_power()
{
}

void power_dump()
{
    char buf[BUFFERSIZE];
    FILE *fp;

    memset(&cur_powerinfo, 0, sizeof(power_info));

    fp = fopen(BATTERY_STATUS_PATH, "r");
    if(fp != 0)
    {
        fgets(buf, BUFFERSIZE, fp);
        strncpy(cur_powerinfo.status, buf, 16);
        fclose(fp);
    }

    fp = fopen(BATTERY_HEALTH_PATH, "r");
    if(fp != 0)
    {
        fgets(buf, BUFFERSIZE, fp);
        sscanf(buf, "%s", cur_powerinfo.health);
        fclose(fp);
    }

    fp = fopen(BATTERY_CAPACITY_PATH, "r");
    if(fp != 0)
    {
        fgets(buf, BUFFERSIZE, fp);
        sscanf(buf, "%d", &cur_powerinfo.capacity);
        fclose(fp);
    }

    fp = fopen(BATTERY_VOLTAGE_PATH, "r");
    if(fp != 0)
    {
        fgets(buf, BUFFERSIZE, fp);
        sscanf(buf, "%d", &cur_powerinfo.voltage);
        fclose(fp);
    }

    fp = fopen(BATTERY_TEMPERATURE_PATH, "r");
    if(fp != 0)
    {
        fgets(buf, BUFFERSIZE, fp);
        sscanf(buf, "%d", &cur_powerinfo.temperature);
        fclose(fp);
    }

    fp = fopen(BATTERY_TECHNOLOGY_PATH, "r");
    if(fp != 0)
    {
        fgets(buf, BUFFERSIZE, fp);
        sscanf(buf, "%s", cur_powerinfo.technology);
        fclose(fp);
    }

    fp = fopen(AC_ONLINE_PATH, "r");
    if(fp != 0)
    {
        fgets(buf, BUFFERSIZE, fp);
        sscanf(buf, "%d", &cur_powerinfo.aconline);
        fclose(fp);
    }

    fp = fopen(USB_ONLINE_PATH, "r");
    if(fp != 0)
    {
        fgets(buf, BUFFERSIZE, fp);
        sscanf(buf, "%d", &cur_powerinfo.usbonline);
        fclose(fp);
    }

}


int get_power_capacity()
{
    return cur_powerinfo.capacity;
}

int get_power_voltage()
{
    return cur_powerinfo.voltage;
}

int get_power_temperature()
{
    return cur_powerinfo.temperature;
}

int get_power_aconline()
{
    return cur_powerinfo.aconline;
}

int get_power_usbonline()
{
    return cur_powerinfo.usbonline;
}

void get_power_health(char *buf)
{
    snprintf(buf, BUFFERSIZE, "%s", cur_powerinfo.health);
    return;
}

void get_power_status(char *buf)
{
    snprintf(buf, BUFFERSIZE, "%s", cur_powerinfo.status);
    return;
}

void get_power_technology(char *buf)
{
    snprintf(buf, BUFFERSIZE, "%s", cur_powerinfo.technology);
    return;
}
